package future;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

public class FutureTaskDemo {

    public static void main(String[] args) throws ExecutionException, InterruptedException {
        FutureTask<String> futureTask = new FutureTask<>(new MyThread());

        Thread thread = new Thread(futureTask, "t1");
        thread.start();

        // 获取返回值
        System.out.println(futureTask.get());
    }

    public static class MyThread implements Callable<String> {

        @Override
        public String call() throws Exception {
            System.out.println("------come in call()");
            return "hello callable";
        }
    }
}
